package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.updateNew.MyIsif;
import org.come.Frame.ZhuFrame;
import org.come.entity.Goodstable;
import org.come.until.Util;

import com.tool.btn.BaptizeBtn;
import com.tool.btn.FormsOnOffBtn;
import com.tool.role.RoleData;
import com.tool.tcpimg.UIUtils;

public class SuitBaptizeJpanel extends JPanel {

    public static boolean saveOld = true;// 判断是否保留原有属性（默认：保留）
    public static BigDecimal sxlxz = new BigDecimal(30);// 所需灵修值: 30点
    public static BigDecimal money = new BigDecimal(1000000);// 所需金钱
    private BaptizeBtn baptizeBtn1,// 开始洗炼|再次洗炼
            baptizeBtn2,// 保留属性
            baptizeBtn3;// 替换属性

    private JLabel[] oldAttr = new JLabel[4];// 旧属性
    private JLabel[] newAttr = new JLabel[4];// 新属性
    private JLabel labtz; // 套装图片
    private JLabel labSave; // 是否保留原属性

    public SuitBaptizeJpanel() {
        this.setPreferredSize(new Dimension(472, 333));
        this.setLayout(null);
        this.setOpaque(false);

        // 关闭按钮事件
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 74);
        offBtn.setBounds(472 - 37, 10, 25, 25);
        this.add(offBtn);

        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        // 旧属性
        for (int i = 0; i < 4; i++) {
            oldAttr[i] = new JLabel("", SwingConstants.CENTER);
            oldAttr[i].setForeground(Color.white);
            oldAttr[i].setFont(UIUtils.TEXT_FONT1);
            if (i % 2 == 0) {
                oldAttr[i].setBounds(49, 232 + (i / 2) * 27, 129, 21);
            } else {
                oldAttr[i].setBounds(184, 232 + (i / 2) * 27, 50, 21);
            }
            this.add(oldAttr[i]);
        }

        // 新属性
        for (int i = 0; i < 4; i++) {
            newAttr[i] = new JLabel("", SwingConstants.CENTER);
            newAttr[i].setForeground(Color.white);
            newAttr[i].setFont(UIUtils.TEXT_FONT1);
            if (i % 2 == 0) {
                newAttr[i].setBounds(259, 232 + (i / 2) * 27, 129, 21);
            } else {
                newAttr[i].setBounds(394, 232 + (i / 2) * 27, 50, 21);
            }
            this.add(newAttr[i]);
        }

        // 套装图片
        labtz = new JLabel("", SwingConstants.CENTER);
        labtz.setBounds(67, 64, 53, 51);
        labtz.addMouseListener(new MouseListener() {
            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ZhuFrame.getZhuJpanel().cleargoodtext();
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                Goodstable goodstable = WashJpanel.getGoodstableBean().getGoodstable();
                if (goodstable == null)
                    return;
                ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
            }
        });
        this.add(labtz);

        // 是否保留原属性
        labSave = new JLabel();
        labSave.setBounds(66, 128, 17, 17);
        labSave.addMouseListener(new MouseListener() {
            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                saveOld = !saveOld;
                if (!saveOld) {
                    money = new BigDecimal(1000000);
                    baptizeBtn2.setBtn(-1);
                    baptizeBtn3.setBtn(-1);
                } else {
                    money = new BigDecimal(1000000);
                    baptizeBtn2.setBtn(1);
                    baptizeBtn3.setBtn(1);
                }
            }
        });
        this.add(labSave);

        // 开始洗炼|再次洗炼
        baptizeBtn1 = new BaptizeBtn("inkImg/button/18.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, "开始洗炼", 1,
                this);
        baptizeBtn1.setBounds(315, 170 - 25, 100, 26);
        this.add(baptizeBtn1);

        // 保留属性
        baptizeBtn2 = new BaptizeBtn("inkImg/button/18.png", -1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, "保留属性", 2,
                this);
        baptizeBtn2.setBounds(72, 320 - 30, 100, 26);
        this.add(baptizeBtn2);

        // 替换属性
        baptizeBtn3 = new BaptizeBtn("inkImg/button/18.png", -1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, "替换属性", 3,
                this);
        baptizeBtn3.setBounds(303, 320 - 30, 100, 26);
        this.add(baptizeBtn3);
        }if (!MyIsif.getStyle().equals("红木")) {
            for (int i = 0; i < 4; i++) {
                oldAttr[i] = new JLabel("", SwingConstants.CENTER);
                oldAttr[i].setForeground(Color.white);
                oldAttr[i].setFont(UIUtils.TEXT_FONT1);
                if (i % 2 == 0) {
                    this.oldAttr[i].setBounds(29, 262 + i / 2 * 27, 129, 21);
                } else {
                    this.oldAttr[i].setBounds(173, 262 + i / 2 * 27, 50, 21);
                }
                this.add(oldAttr[i]);
            }

            // 新属性
            for (int i = 0; i < 4; i++) {
                newAttr[i] = new JLabel("", SwingConstants.CENTER);
                newAttr[i].setForeground(Color.white);
                newAttr[i].setFont(UIUtils.TEXT_FONT1);
                if (i % 2 == 0) {
                    this.newAttr[i].setBounds(239, 262 + i / 2 * 27, 129, 21);
                } else {
                    this.newAttr[i].setBounds(380, 262 + i / 2 * 27, 50, 21);
                }
                this.add(newAttr[i]);
            }

            // 套装图片
            labtz = new JLabel("", SwingConstants.CENTER);
            labtz.setBounds(65, 80, 53, 51);
            labtz.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = WashJpanel.getGoodstableBean().getGoodstable();
                    if (goodstable == null)
                        return;
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labtz);

            // 是否保留原属性
            labSave = new JLabel();
            labSave.setBounds(63, 145, 17, 17);
            labSave.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                    saveOld = !saveOld;
                    if (!saveOld) {
                        money = new BigDecimal(800000);
                        baptizeBtn2.setBtn(-1);
                        baptizeBtn3.setBtn(-1);
                    } else {
                        money = new BigDecimal(1000000);
                        baptizeBtn2.setBtn(1);
                        baptizeBtn3.setBtn(1);
                    }
                }
            });
            this.add(labSave);

            // 开始洗炼|再次洗炼
            baptizeBtn1 = new BaptizeBtn("inkImg/newbutton/B21.png", 1, UIUtils.COLOR_BLACK, UIUtils.TEXT_HY88, "开始洗炼", 1,
                    this);
            baptizeBtn1.setBounds(315, 170, 99, 24);
            this.add(baptizeBtn1);

            // 保留属性
            baptizeBtn2 = new BaptizeBtn("inkImg/newbutton/B21.png", -1, UIUtils.COLOR_BLACK, UIUtils.TEXT_HY88, "保留属性", 2,
                    this);
            baptizeBtn2.setBounds(72, 320, 85, 24);
            this.add(baptizeBtn2);

            // 替换属性
            baptizeBtn3 = new BaptizeBtn("inkImg/newbutton/B21.png", -1, UIUtils.COLOR_BLACK, UIUtils.TEXT_HY88, "替换属性", 3,
                    this);
            baptizeBtn3.setBounds(303, 320, 85, 24);
            this.add(baptizeBtn3);
        }
    }

    private ImageIcon icon, icon1;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        if (icon == null)
            icon = new ImageIcon("inkImg/background/S68.png");
        if (icon1 == null)
            icon1 = new ImageIcon("inkImg/button/B88.png");
        // 背景
        g.drawImage(icon.getImage(), 0, 0, 472, 333, this);
        if (saveOld) {
            g.drawImage(icon1.getImage(), 67, 129, 15, 15, this);
        }
        // 画拥有金钱
        Util.drawMoney(g, 330, 81);
        // 画所需金钱
        if (money != null)
            Util.drawPrice(g, money, 243, 81);
        g.setColor(Color.white);
        // 画拥有的灵修值
        if (RoleData.getRoleData().getLoginResult().getScoretype("灵修值") != null)
            g.drawString(RoleData.getRoleData().getLoginResult().getScoretype("灵修值") + "", 330, 111);
        // 画所需灵修值
        if (sxlxz != null)
            g.drawString(sxlxz + "", 244, 111);
        } else {
            if (icon == null)
                icon = new ImageIcon("img/xy2uiimg/suitbaptize.png");
            if (icon1 == null)
                icon1 = new ImageIcon("img/xy2uiimg/showjadesuit.png");
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 456, 372, this);
            if (saveOld) {
                g.drawImage(icon1.getImage(), 47, 149, 15, 15, this);
            }
            // 画拥有金钱
            Util.drawMoney(g, 310, 101);
            // 画所需金钱
            if (money != null)
                Util.drawPrice(g, money, 223, 101);
            g.setColor(Color.white);
            // 画拥有的灵修值
            if (RoleData.getRoleData().getLoginResult().getScoretype("灵修值") != null)
                g.drawString(RoleData.getRoleData().getLoginResult().getScoretype("灵修值") + "", 310, 131);
            // 画所需灵修值
            if (sxlxz != null)
                g.drawString(sxlxz + "", 244, 131);
        }
    }

    public static BigDecimal getMoney() {
        return money;
    }

    public static void setMoney(BigDecimal money) {
        SuitBaptizeJpanel.money = money;
    }

    public BaptizeBtn getBaptizeBtn1() {
        return baptizeBtn1;
    }

    public void setBaptizeBtn1(BaptizeBtn baptizeBtn1) {
        this.baptizeBtn1 = baptizeBtn1;
    }

    public BaptizeBtn getBaptizeBtn2() {
        return baptizeBtn2;
    }

    public static boolean isSaveOld() {
        return saveOld;
    }

    public static void setSaveOld(boolean saveOld) {
        SuitBaptizeJpanel.saveOld = saveOld;
    }

    public static BigDecimal getSxlxz() {
        return sxlxz;
    }

    public static void setSxlxz(BigDecimal sxlxz) {
        SuitBaptizeJpanel.sxlxz = sxlxz;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

    public void setBaptizeBtn2(BaptizeBtn baptizeBtn2) {
        this.baptizeBtn2 = baptizeBtn2;
    }

    public BaptizeBtn getBaptizeBtn3() {
        return baptizeBtn3;
    }

    public void setBaptizeBtn3(BaptizeBtn baptizeBtn3) {
        this.baptizeBtn3 = baptizeBtn3;
    }

    public JLabel[] getOldAttr() {
        return oldAttr;
    }

    public void setOldAttr(JLabel[] oldAttr) {
        this.oldAttr = oldAttr;
    }

    public JLabel[] getNewAttr() {
        return newAttr;
    }

    public void setNewAttr(JLabel[] newAttr) {
        this.newAttr = newAttr;
    }

    public JLabel getLabtz() {
        return labtz;
    }

    public void setLabtz(JLabel labtz) {
        this.labtz = labtz;
    }

    public JLabel getLabSave() {
        return labSave;
    }

    public void setLabSave(JLabel labSave) {
        this.labSave = labSave;
    }

}
